<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>仓库管理</title>
		<link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css">
	</head>
	<body>
		<script type="text/html" id="toolbarDemo">
		    <div class="layui-btn-container">
		        <button class="layui-btn layui-btn-sm" id="warehouseInsert" lay-event="warehouseInsert">新&nbsp;&nbsp;&nbsp;增</button>
		        <button class="layui-btn layui-btn-sm layui-btn-normal" id="warehouseUpdate" lay-event="warehouseUpdate">修&nbsp;&nbsp;&nbsp;改</button>
		        <button class="layui-btn layui-btn-sm layui-btn-danger" id="warehouseDelete" lay-event="warehouseDelete">删&nbsp;&nbsp;&nbsp;除</button>
		    </div>
		</script>
		<div style="margin: 15px;">
		    <table class="layui-hide" lay-data="{id: 'custId'}" lay-filter="member" id="member"></table>
		</div>
	<script src="../../layui/layui.js" charset="utf-8"></script>
	<script>
	    layui.use(['form', 'table', 'layer'], function(){
	        var tree = layui.tree
	            ,layer = layui.layer
	            ,table = layui.table
	            ,$ = layui.jquery;
            	var data ;
	        table.render({
	            elem: '#member'
	            ,url: '../../../searchDepotInfos'
	            ,id: 'custId'
	            ,toolbar: '#toolbarDemo'
	            ,cols: [[
					{type:'radio'},
	                {type:'depotId',title: '仓库编号',hide:true}
	                ,{field:'depotName', width:100, title: '仓库名称'}
	                ,{field:'empName', width:150, title: '员工编号(负责人)',templet:function (obj) {
							return obj.employeeInfo.empName
                        }}
	                ,{field:'depotPhone', width:120, title: '联系电话'}
	                ,{field:'depotAdress', width:120, title: '仓库地址'}
	                ,{field:'depotState', width: 150 , title: '仓库状态',templet:function (obj) {
							if (obj.depotState == 1){
							    return "启用"
							}else {
							    return "禁用"
							}
                        }}
	                ,{field:'depotDefault', width:120, title: '默认仓库状态'}
	                ,{field:'depotComment', width:120, title: '备注'}
	            ]],
	            limits: [10, 15, 20, 25, 50, 100],
	            page: true
	        });

	        var isflg=false;
            table.on('radio(member)', function(obj){ //test 是 table 标签对应的 lay-filter 属性
                isflg =	obj.checked;
                console.log(isflg)
            });
			console.log(isflg)
			//监听行单击事件（双击事件为：rowDouble）
            table.on('row(member)', function(obj){
                data = obj.data.depotId;
                // console.log(data)
                // $.post("/deleteDepotInfo?depotId="+obj.data.depotId,function (data) {
                // });
            });


            //新增,修改,删除点击按钮功能
            table.on('toolbar(member)', function(obj){

                var checkStatus = table.checkStatus("custId");
                switch(obj.event){
                    case 'warehouseInsert':

                           layer.open({
                               type: 2,
                               title: '仓库添加',
                               scrollbar: false,
                               area: ['700px', '90%'],
                               content: 'warehouseInsert.html'
                           });

                        break;
                    case 'warehouseUpdate':
                        var data = checkStatus.data[0];
                        window.depotInfo = JSON.stringify(data);
                       if(isflg == true){
                           layer.open({
                               type: 2,
                               title: '仓库修改',
                               scrollbar: false,
                               area: ['700px', '90%'],
                               content: 'warehouseUpdate.html'
                           });
                           isflg=false
					   }else {
                           layer.msg("请选择您要修改的仓库!")
					   }
                        break;
                    case 'warehouseDelete':
                       if(isflg==true){

                           layer.confirm('真的删除行么', function(obj){
                               var data = checkStatus.data[0];
                               $.get("/deleteDepotInfo",{depotId: data.depotId},function(row){
                                   if(row = 1){
                                       layer.msg("删除成功")
                                       //表格刷新
									   isflg=false
                                       table.reload('custId');
                                   }else{
                                       layer.msg("删除失败")
                                   }
                               })
                           });
					   }else {
                           layer.msg("您没有选择要删除的仓库!")
					   }
                        break;
                };
            })

	    })
	</script>
	</body>
</html>
